import re
log3 = 'Sep 26 2021 23:11:02-08:00'
print(log3)
m1=r'\d\d:\d\d:\d\d'
print(re.search(m1,log3).group())

log4 = 'MAC move detected, VlanId = 54, MacAddress = 0000-5e00-0136,'
print(log4)
m2=r'\w\w\w\w-\w\w\w\w-\w\w\w\w'
print(re.search(m2,log4).group())

#下面开始学习重复符
log5 = 'MacAddress = 0000-5e00-0136, Original-Port = GE0/0/1, Flapping port = GE0/0/2.'
print(log5)
print(re.search(r'0+',log5).group())
#这里要注意，方法search只会匹配到第一项，从左到右匹配，‘0000’先中了，所以后面的‘00’，‘0’就没有匹配中，即便它们也是符合规则的
#下面再复习一遍分组的概念
print(re.search(r'(00)+',log5).group())
#00被括号括起来了，它们就被正则规则打包成一组，被认为是一个整体，所以'0000'依然匹配
log6 = 'MacAddress = 000000-5e00-0136, Original-Port = GE0/0/1, Flapping port = GE0/0/2.'
print(re.search(r'(00)+',log6).group())

print(re.search(r'(\w+-)+\w+',log4).group())
#重复符的使用再一次得到了验证

print(re.search(r'\w+-(\w+-*)+',log4).group())
# * 重复前面元素零次或多次

string1='abbaaccc'
m3=re.search(r'ac*',string1).group()
print(m3)


email1 = 'zhujiasheng@abc.com'
email2 = 'zhujiasheng@gd.abc.com'
email3 = 'zhujiasheng@st.gd.abc.com'
e1=re.search(r'\S+@(\w+\.)*com',email1).group()
print(e1)
#\S 匹配任何非空白字符
#\w 匹配任何单词字符（字母，数字，下划线）
e2=re.search(r'\S+@(\w+\.)*com',email2).group()
print(e2)
e3=re.search(r'\S+@(\w+\.)*com',email3).group()
print(e3)
ea1=re.search(r'\S+@\S+com',email1).group()
print(ea1)
ea2=re.search(r'\S+@\S+com',email2).group()
print(ea2)
ea3=re.search(r'\S+@\S+com',email3).group()
print(ea3)

# 问号?表示前面的表达式可以0次，或者1次

eb1=re.search(r'\S+@(\w+\.)?com',email1).group()
print(eb1)

log7 = 'MAC move detected, VlanId = 54, MacAddress = 0000-5e00-0136,Sep 26 2021 23:11:02-08:00'
l7=re.search(r'\d{2}:\d{2}:\d{2}',log7).group()
print(l7)
l8=re.search(r'\w{4}-\w{4}-\w{4}',log7).group()
print(l8)